#include "SysAssist.h"
#include <QCryptographicHash>
//#include <QDesktopWidget>
#include <QTime>
#include <QApplication>

SysAssist::SysAssist()
{

}

//MD5加密
QString SysAssist::Encrypt(QString passWd)
{
    QString MD5;
    QByteArray str;
    str = QCryptographicHash::hash(passWd.toLatin1(),QCryptographicHash::Md5);
    MD5.append(str.toHex());
    return (MD5);
}


//生成验证码
QString SysAssist::Verification(int length)
{
    QString s = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,"
                "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,"
                "0,1,2,3,4,5,6,7,8,9";
        QStringList SL = s.split(",");
        QString VC = "";
        qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
        for(int i=0; i<length; i++)
        {
            int n = qrand() % 45;
            VC += SL.at(n);
        }
        return (VC);
}

////可能会多次用到，所以通过调用Helper::center(this)就能使窗口居中，
//void  SysAssist::Center(QWidget *parents)
//{
//    parents->move ((QApplication::desktop()->width() - parents->width())/2,(QApplication::desktop()->height() - parents->height())/2);
//}
